set(png_directory libpng-1.2.35)

if(CMAKEPORTS_ASSEMBLE)
    # This section is used only in CMakePorts SVN
    set(png_directory ${png_directory} PARENT_SCOPE)
    set(png_url http://prdownloads.sourceforge.net/libpng/libpng-1.2.35-no-config.tar.gz PARENT_SCOPE)
    set(png_tarball libpng-1.2.35-no-config.tar.gz  PARENT_SCOPE)
    set(png_patches libpng-1.2.35_cmp.diff PARENT_SCOPE)
endif()

# We can't build both concurrently because a shared png on MSVC causes link
# errors against a static zlib
if(BUILD_SHARED_LIBS)
    set(PNG_SHARED ON)
    set(PNG_STATIC OFF)
else()
    set(PNG_SHARED OFF)
    set(PNG_STATIC ON)
endif()

if(IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/${png_directory}")
    add_subdirectory(${png_directory})
endif()

# Hide these cache variables so as not to confuse CMakePorts users
if(${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}.${CMAKE_PATCH_VERSION}
        VERSION_GREATER 2.6.2)
    unset(PNG_STATIC CACHE)
    unset(PNG_SHARED CACHE)
endif()

# Compatibility settings for interoperability with FindPNG.cmake
set(PNG_FOUND 1 CACHE INTERNAL "libpng found")
set(PNG_INCLUDE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/${png_directory} CACHE INTERNAL "libpng include dir")
set(PNG_LIBRARIES png12 zlib CACHE INTERNAL "libpng libraries including zlib")
set(PNG_LIBRARY png12 CACHE INTERNAL "png library")
if(CYGWIN AND NOT BUILD_SHARED_LIBS)
    set(PNG_DEFINITIONS -DPNG_STATIC)
endif()
